﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CardProperties = Wormhole.Engine.CardLibrary.CardProperties;
using EngineGlyphs = Wormhole.Engine.Glyphs;

namespace Wormhole.UI.Application.Controls.Glyphs
{
	/// <author>Rodney McKay</author>
	/// <date>20 April 2008</date>
	/// <summary>
	/// Render a glyp a character earned.
	/// </summary>
	public partial class Glyph : UserControl
	{
		#region Properties

		#region EngineGlyph
		private EngineGlyphs.EarnedGlyph _engineGlyph;
		/// <summary>
		/// The engine glyph
		/// </summary>
		public EngineGlyphs.EarnedGlyph EngineGlyph
		{
			get
			{
				return this._engineGlyph;
			}

			set
			{
				if (this._engineGlyph != value)
				{
					this._engineGlyph = value;
					this.LoadGlyphProperties();
				}
			}
		}
		#endregion

		#region Experience
		private int _experience;
		/// <summary>
		/// The glyph experience that was earned.
		/// </summary>
		public int Experience 
		{
			get
			{
				return this._experience;
			}

			set
			{
				if (this._experience != value)
				{
					this._experience = value;
					this.DisplayExperience();
				}
			}
		}
		#endregion

		#region Glyph
		private CardProperties.Glyph _glyphType;
		/// <summary>
		/// The glyph to display.
		/// </summary>
		public CardProperties.Glyph GlyphType
		{
			get
			{
				return this._glyphType;
			}

			set
			{
				if (this._glyphType != value)
				{
					this._glyphType = value;
					this.DisplayGlyph();
				}
			}
		}
		#endregion

		#region Skill
		private CardProperties.Skill _skill;
		/// <summary>
		/// The skill that was earned.
		/// </summary>
		public CardProperties.Skill Skill
		{
			get
			{
				return this._skill;
			}

			set
			{
				if (this._skill != value)
				{
					this._skill = value;
					this.DisplaySkill();
				}
			}
		}
		#endregion

		#endregion

		#region Constructor
		/// <summary>
		/// Initialize a default instance of the class.
		/// </summary>
		public Glyph()
		{
			InitializeComponent();
		}

		/// <summary>
		/// Initialize a new instance of the class with a specific glyph.
		/// </summary>
		/// <param name="glyph">The earned engine glyph.</param>
		public Glyph(EngineGlyphs.EarnedGlyph glyph) : this()
		{
			this.EngineGlyph = glyph;
		}
		#endregion

		#region Display Experience
		/// <summary>
		/// Display the experience.
		/// </summary>
		protected void DisplayExperience()
		{
			// get the image url
			string imageUrl = Theme.Theme.ScoreGlyph.Numbers.Number1;
			imageUrl = imageUrl.Replace("1", this.Experience.ToString());

			// load the image
			this.imgNumber.Source = new BitmapImage(new Uri(imageUrl, UriKind.Relative));
		}
		#endregion

		#region Display Glyph
		/// <summary>
		/// Display the glyph.
		/// </summary>
		protected void DisplayGlyph()
		{
			// get the image url
			string imageUrl = "";
			switch (this.GlyphType)
			{
				case CardProperties.Glyph.Gemini:
					imageUrl = Theme.Theme.ScoreGlyph.Glyphs.Gemini;
					break;
				case CardProperties.Glyph.Libra:
					imageUrl = Theme.Theme.ScoreGlyph.Glyphs.Libra;
					break;
				case CardProperties.Glyph.Orion:
					imageUrl = Theme.Theme.ScoreGlyph.Glyphs.Orion;
					break;
				case CardProperties.Glyph.Pisces:
					imageUrl = Theme.Theme.ScoreGlyph.Glyphs.Pisces;
					break;
				case CardProperties.Glyph.Scorpius:
					imageUrl = Theme.Theme.ScoreGlyph.Glyphs.Scorpius;
					break;
				case CardProperties.Glyph.Triangulum:
					imageUrl = Theme.Theme.ScoreGlyph.Glyphs.Triangulum;
					break;
			}

			// load the image
			this.imgGlyph.Source = new BitmapImage(new Uri(imageUrl, UriKind.Relative));
		}
		#endregion

		#region DisplaySkill
		/// <summary>
		/// Display the skill color that was earned
		/// </summary>
		protected void DisplaySkill()
		{
			// get the image url
			Color skillColor = Colors.White;
			switch (this.Skill)
			{
				case CardProperties.Skill.Combat:
					skillColor = Theme.Theme.ScoreGlyph.SkillColors.Combat;
					break;
				case CardProperties.Skill.Culture:
					skillColor = Theme.Theme.ScoreGlyph.SkillColors.Culture;
					break;
				case CardProperties.Skill.Ingenuity:
					skillColor = Theme.Theme.ScoreGlyph.SkillColors.Ingenuity;
					break;
				case CardProperties.Skill.Science:
					skillColor = Theme.Theme.ScoreGlyph.SkillColors.Science;
					break;
			}

			// load the image
			this.backgroundBorder.Background = new SolidColorBrush(skillColor);
		}
		#endregion

		#region Load Glyph Properties
		/// <summary>
		/// Load the glyph properties for unser interface display.
		/// </summary>
		protected void LoadGlyphProperties()
		{
			this.Experience = this.EngineGlyph.Experience;
			this.Skill = this.EngineGlyph.Skill;
			this.GlyphType = this.EngineGlyph.Glyph;
		}
		#endregion
	}
}
